package com.sjsq.service.impl;

import com.sjsq.dao.impl.BookDao;
import com.sjsq.po.Book;

import java.util.ArrayList;
import java.util.List;

/**
 * @author D HS
 * @date 2020/12/02 09:42
 * Book的Service实现层
 */
public class BookServiceImpl implements BookService {

    private BookDao dao = new BookDao() {
        @Override
        public List<Book> select(String sql, Object[] arr) {
            return null;
        }

        @Override
        public Book getBook(Integer id) {
            return null;
        }
    };

    /**
     * 查询所有图书信息
     * @param book
     * @return
     */
    @Override
    public List<Book> select(Book book) {
        StringBuffer sql = new StringBuffer("select * from book where 1 = 1 ");
        List<Object> list = new ArrayList<Object>();
        if(book != null){
            // 根据bookid来查找对应的书籍
            if(book.getBookid() != null && book.getBookid() != 0){
                sql.append(" and bookid = ?");
                list.add(book.getBookid());
            }
        }
        return dao.select(sql.toString(),list.toArray());
    }

    /**
     * 根据图书编号查询信息
     * @param book
     * @return
     */
    @Override
    public Book getBook(Book book) {
        if(book.getBookid() != null && book.getBookid() != 0){
            return dao.getBook(book.getBookid());
        }
        return null;
    }
}